<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$THEME->addBreadcrumb($this->adminUrl.'/change-workspace/', $this->lang('ap_title_change-workspace'));

$VIEW->template = 'admin-thickbox.tpl';

if(get('workspace')!=''){
    // have selected a workspace
    $wsid = (int) get('workspace');
    if($DB->countRows($CONFIG->dbprefix.'admin_users_to_workspaces', "user_id = '{$USER->userid}' AND workspace_id = '{$wsid}'")>0){
        $USER->workspace = $wsid;
        JFX::addSuccess('Workspace has been changed');
        die('<script type="text/javascript">
if(window.parent){
    window.parent.location = "'.$CONFIG->adminUrl.'";
}
</script>');
    }else{
        JFX::addError('You are not permitted to use that workspace');
    }
}

$workspaces = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}workspaces w JOIN {$CONFIG->dbprefix}admin_users_to_workspaces u2w
    ON w.id = u2w.workspace_id WHERE u2w.user_id = '{$USER->userid}' ORDER BY w.title ASC");

$SMARTY->assign('workspaces', $workspaces);

$VIEW->addTemplate('main', 'admin/change-workspace.tpl');


